home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / Link.h < prev    next >
Encoding:
Text File  |  1995-12-11  |  10.8 KB  |  391 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Link.h
  3.  
  4.     Contains:    Link Classes Definition
  5.  
  6.     Written by:    Dave Stafford and Mike Halpin
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- DrawEditor Includes --
  12.  
  13. #ifndef _LINK_
  14. #define _LINK_
  15.  
  16. #ifndef _COMPILERDEFS_
  17. #include "CompDefs.h"
  18. #endif
  19.  
  20. #ifndef _DRAWCONTENT_
  21. #include "DrawContent.h"
  22. #endif
  23.  
  24.  
  25. //=============================================================================
  26. // Forward Declarations
  27. //=============================================================================
  28. class CSelection;
  29. class COrderedList;
  30. class CPromise;
  31. class CShape;
  32. class CCreateLinkCommand;
  33. class CPasteLinkCommand;
  34. class CDragShapeCommand;
  35.  
  36.  
  37. //=============================================================================
  38. //    class CPublishLink
  39. //=============================================================================
  40.  
  41. class CPublishLink
  42. {
  43. public:
  44.     // -- Init --
  45.     
  46.                         CPublishLink(    ODUpdateID updateID, 
  47.                                         CSelection* selection, 
  48.                                         COrderedList* shapeList,
  49.                                         COrderedList* subscribeLinks);
  50.                             
  51.                         CPublishLink (CSelection* selection);
  52.                             
  53.     virtual             ~CPublishLink();
  54.     
  55.     // -- State --
  56.     void                Publish(Environment* ev);
  57.     ODBoolean             PostCloneInternalizeLink(    Environment* ev,  
  58.                                                     ODDraft* toDraft, 
  59.                                                     CShape* shape);
  60.                                                     
  61.     void                 Unpublish(Environment* ev);
  62.     
  63.     void                 AddToPart(Environment* ev);
  64.     void                 RemoveFromPart(Environment *ev);
  65.     
  66.     void                 SetSourcePart(Environment* ev);
  67.     
  68.     ODBoolean             WasRemoved() const;
  69.     ODBoolean             CanDelete() const;
  70.     ODBoolean             IsPublished();
  71.  
  72.     void                 SetHasCommandOutstanding(ODBoolean hasCommand);
  73.     ODBoolean             GetHasCommandOutstanding();    
  74.  
  75.     // -- Updating --
  76.     void                 ContentUpdated(    Environment* ev, 
  77.                                         ODUpdateID updateID, 
  78.                                         ODBoolean forceUpdate = kODFalse);
  79.     
  80.     void                ExternalizeLinkContent(Environment* ev, ODStorageUnit* linkSU);
  81.  
  82.     // -- Content --
  83.     void                 AddShape(CShape* shape);
  84.     void                 AddShape(Environment* ev, CShape* shape);
  85.     
  86.     void                 RemoveShape(CShape *shape);
  87.     void                 ShapeSelected(ODBoolean selectState);
  88.     ODULong             Count();
  89.     
  90.     // -- Data Transfer and Storage --
  91.     void                 ExternalizeLink(Environment *ev, 
  92.                                         ODStorageUnit* su, 
  93.                                         CCloneInfo* cloneInfo);
  94.                                         
  95.     ODBoolean             InternalizeLink(Environment *ev,  
  96.                                         ODStorageUnit *su,  
  97.                                         CCloneInfo *cloneInfo, 
  98.                                         CShape** shapeTable);
  99.                                         
  100.     // -- User Interface --
  101.     void                 ShowLinkInfoDialog(Environment* ev);
  102.     void                 RevealLink(Environment* ev);
  103.         
  104.     // -- Misc Accessors --
  105.     ODLinkSource*        GetODLinkSource() const;
  106.     
  107.     ODUpdateID            GetUpdateID() const;
  108.     ODUpdateID            GetPendingID() const;
  109.     void                SetPendingID(ODUpdateID id);
  110.     
  111. private:
  112.     ODLinkSource*        fODLinkSource;
  113.     ODID                fODID;
  114.     
  115.     ODUpdateID            fUpdateID;
  116.     ODUpdateID            fPendingID;
  117.     
  118.     CSelection*            fSelection;
  119.     DrawEditor*            fDrawEditor;
  120.  
  121.     COrderedList*        fShapeList;
  122.     CDrawContent*        fPublishContent;
  123.     CPromise*            fPromise;
  124.     COrderedList*         fSubscribeLinks;  // temporary list when link is not in content
  125.         
  126.     ODBoolean            fWasRemoved;
  127.     ODBoolean            fPublished;
  128.     ODBoolean            fHasCommandOutstanding;
  129.     ODBoolean            fNewlyPublished;
  130.     
  131.     ODUShort            fSelectedCount;
  132.     
  133. };
  134.  
  135. // Typedef for linkspec data
  136. typedef struct
  137. {
  138.     ODUpdateID             fUpdateID;
  139.     CDragShapeCommand*    fCommand;
  140.  
  141. }  LinkSpecData;
  142.  
  143.  
  144. //=============================================================================
  145. //    class CSubscribeLink
  146. //=============================================================================
  147.  
  148. class CSubscribeLink
  149. {
  150. public:
  151.     // -- Init --
  152.                     CSubscribeLink(    ODLink* odLink, 
  153.                                     CSelection* selection,
  154.                                     ODLinkInfo& linkInfo, 
  155.                                     ODPasteAsResult& paResult, 
  156.                                     ODBoolean defaultIsMerge);
  157.                                         
  158.                     CSubscribeLink(CSelection* selection);
  159.                     
  160.     virtual         ~CSubscribeLink();
  161.  
  162.     // -- Link State --
  163.     void            Subscribe(Environment* ev);
  164.     ODBoolean         PostCloneInternalizeLink(    Environment* ev,  
  165.                                                 ODDraft* toDraft, 
  166.                                                 CShape* shape);
  167.                                                 
  168.     void              Unsubscribe(Environment* ev);
  169.  
  170.     void             Publish(Environment* ev, CPublishLink* publishLink);
  171.     void              Unpublish(Environment* ev, CPublishLink* publishLink);
  172.  
  173.     void             AddToPart(Environment *ev);
  174.     void             RemoveFromPart(Environment* ev, ODBoolean doRemove = kODTrue);
  175.     
  176.     void             Register(Environment* ev);
  177.     void             Unregister(Environment* ev);
  178.     ODBoolean         IsRegistered();
  179.     
  180.     void             SetCommand(CPasteLinkCommand* command);
  181.  
  182.     // -- Link Content --
  183.     void            LinkUpdated(Environment* ev, ODUpdateID id);
  184.  
  185.     void             AddShape(Environment* ev, CShape* shape);
  186.     void             AddShape(CShape* shape);
  187.     void             RemoveShape(CShape* shape);
  188.  
  189.     void             ShapeSelected(ODBoolean selectState);
  190.  
  191.     void             AddToSelection(Environment* ev, ODBoolean drawHandles);
  192.     void             RemoveShapes(Environment* ev, ODBoolean commit);
  193.  
  194.     // -- Data Transfer and Storage --
  195.     void             ExternalizeLink(Environment *ev, ODStorageUnit* su, CCloneInfo* cloneInfo);
  196.     ODBoolean         InternalizeLink( Environment *ev,  ODStorageUnit *su,  CCloneInfo *cloneInfo, CShape** shapeTable);
  197.  
  198.     // -- User Interface --
  199.     void             ShowCantEditDialog(Environment* ev);
  200.     void             ShowLinkInfoDialog(Environment* ev);
  201.     
  202.     void             SetOriginPoint(ODPoint newOrigin);
  203.  
  204.     // -- Misc. Accessors --
  205.     ODLink*         GetODLink() const;
  206.     COrderedList*     GetPublishLinks();
  207.     ODULong         Count();
  208.  
  209.         
  210. private:
  211.     ODLink*                fODLink;
  212.     ODID                fODID;
  213.     
  214.     CSelection*            fSelection;
  215.     DrawEditor*            fDrawEditor;
  216.     
  217.     COrderedList*         fShapeList;
  218.     CSubscribeContent*    fSubscribeContent;
  219.     COrderedList*        fPublishLinks;
  220.     
  221.     ODLinkInfo            fLinkInfo;
  222.     ODPasteAsResult        fPasteAsResult;
  223.     ODBoolean            fDefaultIsMerge;
  224.     
  225.  
  226.     ODBoolean            fRegistered;    
  227.     CPasteLinkCommand*    fCommand;
  228.     ODBoolean            fWasRemoved;        // Was link removed from the part using RemoveFromPart?
  229.     ODBoolean            fRemovedShapes;        // Did the link remove shapes from the part in RemoveFromPart?    
  230.     
  231.     ODPoint                fOriginPoint;
  232.     ODUShort            fSelectedCount;
  233. };
  234.  
  235. //=============================================================================
  236. //    CPublishLink Inlines
  237. //=============================================================================
  238.  
  239. //-----------------------------------------------------------------------------
  240. //    CPublishLink::GetODLinkSource
  241. //-----------------------------------------------------------------------------
  242. inline ODLinkSource* CPublishLink::GetODLinkSource() const
  243. {
  244.     return fODLinkSource;
  245. }
  246.  
  247. //-----------------------------------------------------------------------------
  248. //    CPublishLink::CanDelete
  249. //
  250. //    Description:    If the link is neither published nor cached in a command
  251. //    then it's ok to delete it.
  252. //-----------------------------------------------------------------------------
  253. inline ODBoolean CPublishLink::CanDelete() const
  254. {
  255.     return !fPublished && !fHasCommandOutstanding;
  256. }
  257.  
  258. //-----------------------------------------------------------------------------
  259. //    CPublishLink::GetUpdateID
  260. //-----------------------------------------------------------------------------
  261. inline ODUpdateID    CPublishLink::GetUpdateID() const
  262. {
  263.     return fUpdateID;
  264. }
  265.  
  266. //-----------------------------------------------------------------------------
  267. //    CPublishLink::GetPendingID
  268. //-----------------------------------------------------------------------------
  269. inline ODUpdateID    CPublishLink::GetPendingID() const
  270. {
  271.     return fPendingID;
  272. }
  273.  
  274. //-----------------------------------------------------------------------------
  275. //    CPublishLink::SetPendingID
  276. //-----------------------------------------------------------------------------
  277. inline void    CPublishLink::SetPendingID(ODUpdateID id)
  278. {
  279.     fPendingID = id;
  280. }
  281.  
  282. //---------------------------------------------------------------------------------------
  283. //    CPublishLink::WasRemoved
  284. //
  285. //    Description:  kODTrue if RemoveFromPart was called and AddToPart hasn't been called
  286. //    since.
  287. //---------------------------------------------------------------------------------------
  288.  
  289. inline ODBoolean CPublishLink::WasRemoved() const
  290. {
  291.     return fWasRemoved;
  292. }
  293.  
  294. //---------------------------------------------------------------------------------------
  295. //    CPublishLink::IsPublished
  296. //
  297. //    Description:    kODTrue if Publish or PostCloneInternalizeLink was called, and Unpublish
  298. //     has not been called since then.
  299. //---------------------------------------------------------------------------------------
  300.  
  301. inline ODBoolean CPublishLink::IsPublished()
  302. {
  303.     return fPublished;
  304. }
  305.  
  306.  
  307. //---------------------------------------------------------------------------------------
  308. //    CPublishLink::SetHasCommandOutstanding
  309. //
  310. //    Description:    Set fHasCommandOutstanding to indicate if there is a reference to 
  311. //     this in a command object.
  312. //---------------------------------------------------------------------------------------
  313.  
  314. inline void CPublishLink::SetHasCommandOutstanding(ODBoolean hasCommand)
  315. {
  316.     fHasCommandOutstanding = hasCommand;
  317. }
  318.  
  319.  
  320. //---------------------------------------------------------------------------------------
  321. //    CPublishLink::GetHasCommandOutstanding
  322. //
  323. //    Description:    kODTrue if this is refernced in a command object.
  324. //---------------------------------------------------------------------------------------
  325.  
  326. inline ODBoolean CPublishLink::GetHasCommandOutstanding()
  327. {
  328.     return fHasCommandOutstanding;
  329. }
  330.  
  331. //=============================================================================
  332. //    CSubscribeLink Inlines
  333. //=============================================================================
  334.  
  335. //-----------------------------------------------------------------------------
  336. //    CSubscribeLink::GetODLink
  337. //-----------------------------------------------------------------------------
  338. inline ODLink* CSubscribeLink::GetODLink() const
  339. {
  340.     return fODLink;
  341. }
  342.  
  343. //-----------------------------------------------------------------------------
  344. //    CSubscribeLink::IsRegistered
  345. //-----------------------------------------------------------------------------
  346.  
  347. inline ODBoolean CSubscribeLink::IsRegistered()
  348. {
  349.     return fRegistered;
  350. }
  351.  
  352.  
  353. //-----------------------------------------------------------------------------
  354. //    CSubscribeLink::SetCommand
  355. //
  356. //    Description:  Set the fCommand field for adding a kODEndAction asynchronously
  357. //-----------------------------------------------------------------------------
  358.  
  359. inline void CSubscribeLink::SetCommand(CPasteLinkCommand* command)
  360. {
  361.     fCommand = command;
  362. }
  363.  
  364. //-----------------------------------------------------------------------------
  365. //    CSubscribeLink::SetOriginPoint
  366. //
  367. //    Description:    Set the default location for the next update to be drawn at
  368. //    used when 'Dropping' a link.
  369. //-----------------------------------------------------------------------------
  370.  
  371. inline void CSubscribeLink::SetOriginPoint(ODPoint newOrigin)
  372. {
  373.     fOriginPoint = newOrigin;
  374. }
  375.  
  376. //-----------------------------------------------------------------------------
  377. //    CSubscribeLink::GetPublishLinks
  378. //
  379. //    Description:    Return the list of publishers in which this subscriber is 
  380. //    contained.
  381. //-----------------------------------------------------------------------------
  382.  
  383. inline COrderedList* CSubscribeLink::GetPublishLinks()
  384. {
  385.     return fPublishLinks;
  386. }
  387.  
  388. #endif
  389.  
  390.  
  391.